
package com.dps.omc.service.impl;
import com.dps.omc.model.Artifact;
import com.dps.omc.service.IArtifactService;
import com.dps.common.utils.IdGenerator;
import com.dps.omc.service.ISubjectArtifactService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dps.common.service.impl.AbstractPageService;
import com.dps.omc.dao.ISubjectArtifactDAO;
import com.dps.omc.model.SubjectArtifact;

import java.util.List;

@SuppressWarnings("unchecked")
@Service("SubjectArtifactServiceImpl")

public class SubjectArtifactServiceImpl extends AbstractPageService<ISubjectArtifactDAO,SubjectArtifact> implements ISubjectArtifactService {

	@Autowired
	private ISubjectArtifactDAO subjectArtifactDAO;
	@Autowired
	private IArtifactService artifactService;
	@Override
	public boolean getEnableDataPerm() {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public ISubjectArtifactDAO getDao() {
		return subjectArtifactDAO;
	}

	@Override
	public void create(String subjectId, List<SubjectArtifact> subjectArtifacts) {

		this.deleteByProperty("subjectId",subjectId);
		int seq = 1;
		for(SubjectArtifact subjectArtifact:subjectArtifacts)
		{
			Artifact artifact = artifactService.fetch(subjectArtifact.getArtifactId());
			subjectArtifact.setId(IdGenerator.createNewId());
			subjectArtifact.setSubjectId(subjectId);
			subjectArtifact.setArtifactName(artifact.getName());
			subjectArtifact.setArtifactPath(artifact.getPath());
			subjectArtifact.setArtifactSize(artifact.getSizeLength());
			subjectArtifact.setSeq(seq);
			subjectArtifact.setWarnFlag(artifact.getWarnFlag());
			this.add(subjectArtifact);
			seq++;
		}
	}

	@Override
	public List<SubjectArtifact> findListBySubjectId(String subjectId) {
		return getDao().findListBySubjectId(subjectId);
	}
}
